//
//  CircleCollectionReusableView.m
//  14-礼物说
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "CircleCollectionReusableView.h"
#import "CircleCollectionViewCell.h"

@interface CircleCollectionReusableView ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) NSMutableArray *dataArray;
@end
@implementation CircleCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        [self addSubview:_label];
        _label.textColor = [UIColor blackColor];
        _label1 = [[UILabel alloc] initWithFrame:CGRectMake(374 - 120, 0, 100, 50)];
        [self addSubview:_label1];
        _label1.textColor = [UIColor blackColor];
        _label1.text = @"查看全部";
        _label1.textAlignment = 2;
        _myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(374 - 20, 15, 20, 20)];
        [self addSubview:_myImageView];
        _myImageView.image = [UIImage imageNamed:@"13"];
        [self createCollectionView];
    }
    return self;
}
- (void)createCollectionView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(354, 140);
    flowLayout.minimumLineSpacing = 20;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, self.bounds.size.width, self.bounds.size.height - 50) collectionViewLayout:flowLayout];
    _collect.delegate = self;
    _collect.dataSource = self;
    [self addSubview:_collect];
    _collect.pagingEnabled = YES;
    [_collect registerClass:[CircleCollectionViewCell class] forCellWithReuseIdentifier:@"5"];
    _collect.backgroundColor = [UIColor whiteColor];
    // 创造数据
    _dataArray = [NSMutableArray array];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
    NSDictionary *dataDic = [NSDictionary dictionaryWithContentsOfFile:path];
    for (NSDictionary *dic in dataDic[@"circle"]) {
        MyGirl *girl = [[MyGirl alloc] init];
        [girl setValuesForKeysWithDictionary:dic];
        [_dataArray addObject:girl];
    }
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CircleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"5" forIndexPath:indexPath];
    MyGirl *girl = _dataArray[indexPath.row];
    cell.myImageView.image = [UIImage imageNamed:girl.tupian];
    cell.label.text = girl.label;
    cell.label1.text = girl.label1;
    cell.label2.text = girl.label2;
    return cell;
}
@end
